package com.fubowen.lepton.ui.home.suggest

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.SortedList
import com.fubowen.lepton.R
import com.fubowen.lepton.bean.Suggest

class SuggestAdapter : RecyclerView.Adapter<SuggestViewHolder>() {

    private var sortedList: SortedList<Suggest>? = null

    override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): SuggestViewHolder {
        val view = LayoutInflater.from(viewGroup.context)
            .inflate(R.layout.fragment_home_suggest, viewGroup, false)
        return SuggestViewHolder(view)
    }

    override fun onBindViewHolder(viewHolder: SuggestViewHolder, position: Int) {
        viewHolder.bind(sortedList?.get(position))
    }

    override fun getItemCount() = sortedList?.size() ?: 0

    fun setDataSource(_sortedList: SortedList<Suggest>) {
        sortedList = _sortedList
    }

    fun getDataSource() = sortedList

}